﻿cmake_minimum_required(VERSION 2.8.11)
project(UDP_Forward)

set(TargetAppName "udp_forward")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake_modules)
include(CMakePrintHelpers) 
#LibEvent2
set(Libevent2NeedComponents)
if(WIN32)
	#windows下只链接到event.lib
	set(Libevent2NeedComponents COMPONENTS core )
else()
	#linux下需要libevent-pthreads,libevent-core,libevent-extra
	set(Libevent2NeedComponents	 COMPONENTS pthreads extra core)
endif()
find_package(LIBEVENT2 MODULE ${Libevent2NeedComponents} REQUIRED)
if(NOT LIBEVENT2_FOUND)
	message(FATAL_ERROR  "can not find LIBEVENT2")
endif()

cmake_print_variables(CMAKE_MODULE_PATH)


#设置include目录	
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
include
${LIBEVENT2_INCLUDE_DIRS}
)




#增加可执行目标生成
add_executable(${TargetAppName} 
src/main.cpp)

if(WIN32)
target_compile_definitions(${TargetAppName}  
PRIVATE 
_SCL_SECURE_NO_WARNINGS  
_CRT_SECURE_NO_WARNINGS 
WIN32_LEAN_AND_MEAN
_WINSOCK_DEPRECATED_NO_WARNINGS)
endif()

#C++11 编译特性允许
#target_compile_features(${TargetAppName} PRIVATE cxx_std_11)
#set_target_properties(${TargetAppName} PROPERTIES CXX_EXTENSIONS OFF)
	
#目标链接库文件		
target_link_libraries("${TargetAppName}" 
${LIBEVENT2_LIBRARIES}
)

if(WIN32)
target_link_libraries(
"${TargetAppName}" 
ws2_32.lib
)
endif()
